package Week.W155;

import org.junit.Test;

import java.util.*;

public class Solution01 {

    public List<List<Integer>> minimumAbsDifference(int[] arr) {
        Arrays.sort(arr);
        int[] dp = new int[arr.length - 1];
        int min = Integer.MAX_VALUE;
        for (int i = 1; i < arr.length; i++) {
            dp[i - 1] = arr[i] - arr[i - 1];
            min = Math.min(dp[i - 1], min);
        }

        List<List<Integer>> result = new ArrayList<>();
        for (int i = 0; i < dp.length; i++) {
            if (dp[i] == min) {
                List<Integer> temp = new ArrayList<>();
                temp.add(arr[i]);
                temp.add(arr[i + 1]);
                result.add(temp);
            }
        }
        return result;
    }


    public int nthUglyNumber(int n, int a, int b, int c) {
        long ia = b/a, ib = 1, ic = 1;
        long cur =ia*a;


        for (int i = (int) ia; i <= n; i++) {
            long min = Math.min(cur * a, Math.min(cur * b, cur * c));
            min = Math.min(ia * a, Math.min(ib * b, Math.min(ic * c, min)));

            ia=min/a+1;
            ib=min/b+1;
            ic=min/c+1;
           /* while (ia * a <= min) {
                ia++;
            }
            while (ib * b <= min) {
                ib++;
            }
            while (ic * c <= min) {
                ic++;
            }
*/

            cur = min;
        }

        return (int) cur;
    }

    /* public int nthUglyNumber(int n, int a, int b, int c) {
         List<Integer
         while (n > 0) {

         }
     }
 */
    @Test
    public void test() {
      /* int[] t=new int[]{4,2,1,3};
       minimumAbsDifference(t);*/
     //    System.out.println(nthUglyNumber(3, 2, 3, 5));
    //    System.out.println(nthUglyNumber(4, 2, 3, 4));
     //      System.out.println(nthUglyNumber(5, 2, 11, 13));
        System.out.println(nthUglyNumber(1000000000, 2, 217983653, 336916467));
        // System.out.println(reverseParentheses(test1));
        // System.out.println(reverseParentheses(test1));
        //  System.out.println(reverseParentheses(test3));

    }
}
